<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客房列表</title>
<jsp:include page="/layout/_css.jsp"/>
</head>
<body>
	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight">
			<div class="row">
				<div class="col-sm-12">
					  <div class="ibox float-e-margins">
					  	 <div class="ibox-title">
					  	 	<h5>客房列表</h5>
					  	 </div>
					  	 <div class="ibox-content">
			    			 <table id="table"></table>
					  	 	 <div class="btn btn-primary" onclick='deleteSelect()'>删除所选</div>
					  	 </div>
					  </div>
				</div>
			</div>	
		</div>
		<div id="updRoom" style="display: none;">
			<div class="wrapper wrapper-content animated fadeInRight">
				<div class="ibox-content">
					<form action="" method="get"
						class="form-horizontal">
						<div class="form-group">
							<label class="col-sm-2 control-label">房间类型</label>
		
							<div class="col-sm-10">
								<input type="text" name="r_type" class="form-control"
									value="" readonly="readonly">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">房间价格</label>
		
							<div class="col-sm-10">
								<input type="text" name="r_price" class="form-control"
									>
							</div>
						</div>
						
						<div class="hr-line-dashed"></div>
						<div class="form-group">
							<div class="col-sm-4 col-sm-offset-2">
								<input class="btn btn-primary" type="button" onclick="updRoomByType()" value="提交">
								<input class="btn btn-white" type="button" onclick="closeLayer()" value="取消">
							</div>
						</div>
					</form>
				</div>
			</div>

		</div>
	</body>
</body>

<jsp:include page="/layout/_script.jsp"></jsp:include>
<script src="https://cdn.bootcss.com/bootstrap-table/1.12.1/bootstrap-table.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.js"></script>
<script>
$('#table').bootstrapTable({
    url: '${ctx}/UserServlet/listAllRoom',
    columns: [
    	{
    	checkbox:true
    	},{
        field: 'r_num',
        title: '房间号',
        sortable:true
    }, {
        field: 'r_type',
        title: '房间类型'
    },{
        field: 'r_price',
        title: '房间价格',
    },{
        field: 'r_bad',
        title: '房间床型'
    },{
        field: 'r_order',
        title: '是否预订'
    },{
    	field: 'caozuo',
        title: '操作',
        formatter:function(v1,v2,v3){
        	return ['<a class="like" href="javascript:void(0)" title="Like">',
                '<i class="fa fa-pencil"></i>',
                '</a>'].join('');
        },
        events:'caozuoEvents'
    }],
    pagination:true,
    pageSize:10,
    pageList:[5,10,20],
    search:true,
    showColumns:true,
    clickToSelect:true,
    sidePagination:'server',
    rowStyle:function(v,index){
    	var classes = ['active', 'success', 'info', 'warning', 'danger'];
        return {}; 
    }
});

window.caozuoEvents = {
        'click .like': function (e, value, row) {
        	$('[name=r_type]').val(row.r_type);
        	$('[name=r_price]').val(row.r_price);
    		layer.open({
    			type:1,
    			content:$('#updRoom'),
    			area: ['800px', '300px'],
    			offset:'70px',
    			title:'房间信息修改',
    			fixed:true,
    		});
        }
    };
function updRoomByType(){
	if(confirm('是否修改')){
		$.ajax({
			url:'${ctx}/UserServlet/updRoomByType',
			type:'post',
			data:{"r_type":$("[name=r_type]").val(),"r_price":$("[name=r_price]").val()},
			success:function(r){
				if(r){
					layer.closeAll();
					layer.msg("修改了"+r+"行数据");
					time:5000;
				    $('#table').bootstrapTable('refresh');
				}else{
					layer.msg("修改失败");
				}
			}
		});
	}
}
function closeLayer(){
	layer.closeAll();
	$('#table').bootstrapTable('refresh');
}
</script>
</html>